﻿using FirstHomeWork.Thread.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FirstHomeWork.Thread
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 开始
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStart_Click(object sender, EventArgs e)
        {
            List<string> strList = CustomConfigManager.GetEventList("Character");

            List<string> xiaoFengList = CustomConfigManager.GetEventList("XiaoFeng");
            List<string> xuZhuList = CustomConfigManager.GetEventList("XuZhu");
            List<string> duanYuList = CustomConfigManager.GetEventList("DuanYu");

            List<Task> taskList = new List<Task>();

            TaskFactory taskFactory = new TaskFactory();
            strList.ForEach(p =>
            {
                taskList.Add(taskFactory.StartNew(o=> this.ShowRtx(p),""));
            });
            taskFactory.ContinueWhenAny(taskList.ToArray(), arry => this.Invoke(new Action(() =>
              {
                  rtxShow.Text = "天龙八部就此拉开序幕。。。。";
              })));
        }

        private void ShowRtx(string str)
        {
            this.Invoke(new Action(() =>
            {
                rtxShow.Text = str;
            }));
        }
    }
}
